package cn.dxh.stagefinal.controller;

import cn.dxh.stagefinal.bean.Sendback;
import cn.dxh.stagefinal.config.PageConfig;
import cn.dxh.stagefinal.service.SendbackService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SendbackController {

    @Autowired
    private SendbackService sendbackService;

    @RequestMapping("/order/findbacks")
    public String getOrders(@RequestParam(defaultValue = "1") Integer pageindex, String
            backnum, String source, String backdate, String username, Integer backstate,ModelMap modelMap){
        PageInfo<Sendback> pageInfo = sendbackService.findBacks(pageindex, PageConfig.PAGE_SIZE, backnum, source, backdate, username,backstate);
        modelMap.addAttribute("pageInfo",pageInfo);
        modelMap.addAttribute("backnum",backnum);
        modelMap.addAttribute("source",source);
        modelMap.addAttribute("backdate",backdate);
        modelMap.addAttribute("username",username);
        modelMap.addAttribute("backstate",backstate);
        modelMap.addAttribute("pageindex",pageindex);
        modelMap.addAttribute("pages",pageInfo.getPages());
        return "/order/backsend";
    }

    @RequestMapping("/order/findback")
    public String getOne(Integer backid,ModelMap modelMap){
        Sendback sendback = sendbackService.getOne(backid);
        modelMap.addAttribute("back",sendback);
        return "/order/backview";
    }
}
